-- Copyright (c) 2024 Huawei Technologies Co., Ltd.
-- openUBMC is licensed under Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at:
--          http://license.coscl.org.cn/MulanPSL2
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-- See the Mulan PSL v2 for more details.
local mdb = require 'mc.mdb'
local class = require 'mc.class_mgnt'
local privilege = require 'mc.privilege'

local spdm_component_class_types = require 'class.types.SpdmComponent'
local trusted_component_intf_types = require 'spdm.json_types.TrustedComponent'
local properties_intf_types = require 'spdm.json_types.Properties'
local component_integrity_intf_types = require 'spdm.json_types.ComponentIntegrity'
local measurement_set_intf_types = require 'spdm.json_types.MeasurementSet'
local spdm_measurement_intf_types = require 'spdm.json_types.SPDMMeasurement'
local certificate_intf_types = require 'spdm.json_types.Certificate'

local TrustedComponent = {
    ['mdb_prop_configs'] = {
        ['bmc.kepler.RoT.TrustedComponent'] = {
            ['Name'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = trusted_component_intf_types.Name
            },
            ['Type'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['enum'] = {'Discrete', 'Integrated'},
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = trusted_component_intf_types.Type
            },
            ['TargetComponent'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = trusted_component_intf_types.TargetComponent
            }
        },
        ['bmc.kepler.Object.Properties'] = {
            ['ClassName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ClassName
            },
            ['ObjectName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ObjectName
            },
            ['ObjectIdentifier'] = {
                ['baseType'] = 'Struct',
                ['$ref'] = '#/defs/StructIdentifier',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ObjectIdentifier
            }
        }
    },
    ['mdb_classes'] = mdb.get_class_obj('/bmc/kepler/Chassis/:ChassisId/TrustedComponents/:DeviceName'),
    ['new_mdb_objects'] = mdb.new_objects_builder({
        ['bmc.kepler.RoT.TrustedComponent'] = {
            ['property_defaults'] = {
                ['Name'] = trusted_component_intf_types.Name.default[1],
                ['Type'] = trusted_component_intf_types.Type.default[1],
                ['TargetComponent'] = trusted_component_intf_types.TargetComponent.default[1]
            },
            ['privileges'] = {
                ['props'] = {
                    ['Name'] = {['read'] = privilege.ReadOnly},
                    ['Type'] = {['read'] = privilege.ReadOnly},
                    ['TargetComponent'] = {['read'] = privilege.ReadOnly}
                }
            },
            ['interface_types'] = trusted_component_intf_types
        },
        ['bmc.kepler.Object.Properties'] = {
            ['property_defaults'] = {
                ['ClassName'] = properties_intf_types.ClassName.default[1],
                ['ObjectName'] = properties_intf_types.ObjectName.default[1],
                ['ObjectIdentifier'] = properties_intf_types.ObjectIdentifier.default[1]
            },
            ['interface_types'] = properties_intf_types
        }
    })
}

local ComponentIntegrity = {
    ['mdb_prop_configs'] = {
        ['bmc.kepler.RoT.ComponentIntegrity'] = {
            ['Type'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['enum'] = {'SPDM', 'TPM'},
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = component_integrity_intf_types.Type
            },
            ['Version'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = component_integrity_intf_types.Version
            },
            ['LastUpdated'] = {
                ['baseType'] = 'U64',
                ['readOnly'] = true,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = component_integrity_intf_types.LastUpdated
            }
        },
        ['bmc.kepler.RoT.ComponentIntegrity.MeasurementSet'] = {
            ['Specification'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['enum'] = {'DMTF'},
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = measurement_set_intf_types.Specification
            },
            ['SummaryType'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['enum'] = {'All', 'TCB'},
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = measurement_set_intf_types.SummaryType
            },
            ['SummaryHashAlgorithm'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = measurement_set_intf_types.SummaryHashAlgorithm
            },
            ['SummaryHash'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = measurement_set_intf_types.SummaryHash
            }
        },
        ['bmc.kepler.Object.Properties'] = {
            ['ClassName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ClassName
            },
            ['ObjectName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ObjectName
            },
            ['ObjectIdentifier'] = {
                ['baseType'] = 'Struct',
                ['$ref'] = '#/defs/StructIdentifier',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ObjectIdentifier
            }
        }
    },
    ['mdb_method_configs'] = {
        ['bmc.kepler.RoT.ComponentIntegrity.MeasurementSet'] = {
            ['SPDMGetSignedMeasurements'] = {
                ['req'] = {
                    {['baseType'] = 'U8[]', ['param'] = 'MeasurementIndices'},
                    {['baseType'] = 'U8', ['minimum'] = 0, ['maximum'] = 15, ['param'] = 'SlotId'},
                    {['baseType'] = 'String', ['minLength'] = 64, ['maxLength'] = 64, ['param'] = 'Nonce'}
                },
                ['rsp'] = {
                    {['baseType'] = 'String', ['param'] = 'Version'},
                    {['baseType'] = 'String', ['param'] = 'PublicKey'},
                    {['baseType'] = 'String', ['param'] = 'HashingAlgorithm'},
                    {['baseType'] = 'String', ['param'] = 'SigningAlgorithm'},
                    {['baseType'] = 'String', ['param'] = 'SignedMeasurements'}
                },
                ['privilege'] = {'SecurityMgmt'}
            }
        }
    },
    ['mdb_classes'] = mdb.get_class_obj(
        '/bmc/kepler/Chassis/:ChassisId/TrustedComponents/:DeviceName/ComponentIntegrity/:Id'),
    ['new_mdb_objects'] = mdb.new_objects_builder({
        ['bmc.kepler.RoT.ComponentIntegrity'] = {
            ['property_defaults'] = {
                ['Type'] = component_integrity_intf_types.Type.default[1],
                ['Version'] = component_integrity_intf_types.Version.default[1],
                ['LastUpdated'] = component_integrity_intf_types.LastUpdated.default[1]
            },
            ['privileges'] = {
                ['props'] = {
                    ['Type'] = {['read'] = privilege.ReadOnly},
                    ['Version'] = {['read'] = privilege.ReadOnly},
                    ['LastUpdated'] = {['read'] = privilege.ReadOnly}
                }
            },
            ['interface_types'] = component_integrity_intf_types
        },
        ['bmc.kepler.RoT.ComponentIntegrity.MeasurementSet'] = {
            ['property_defaults'] = {
                ['Specification'] = measurement_set_intf_types.Specification.default[1],
                ['SummaryType'] = measurement_set_intf_types.SummaryType.default[1],
                ['SummaryHashAlgorithm'] = measurement_set_intf_types.SummaryHashAlgorithm.default[1],
                ['SummaryHash'] = measurement_set_intf_types.SummaryHash.default[1]
            },
            ['privileges'] = {
                ['props'] = {
                    ['Specification'] = {['read'] = privilege.ReadOnly},
                    ['SummaryType'] = {['read'] = privilege.ReadOnly},
                    ['SummaryHashAlgorithm'] = {['read'] = privilege.ReadOnly},
                    ['SummaryHash'] = {['read'] = privilege.ReadOnly}
                },
                ['methods'] = {['SPDMGetSignedMeasurements'] = privilege.SecurityMgmt}
            },
            ['interface_types'] = measurement_set_intf_types
        },
        ['bmc.kepler.Object.Properties'] = {
            ['property_defaults'] = {
                ['ClassName'] = properties_intf_types.ClassName.default[1],
                ['ObjectName'] = properties_intf_types.ObjectName.default[1],
                ['ObjectIdentifier'] = properties_intf_types.ObjectIdentifier.default[1]
            },
            ['interface_types'] = properties_intf_types
        }
    })
}

local SPDMMeasurement = {
    ['mdb_prop_configs'] = {
        ['bmc.kepler.RoT.ComponentIntegrity.SPDMMeasurement'] = {
            ['Index'] = {
                ['baseType'] = 'U8',
                ['readOnly'] = true,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = spdm_measurement_intf_types.Index
            },
            ['HashAlgorithm'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = spdm_measurement_intf_types.HashAlgorithm
            },
            ['MeasurementType'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['enum'] = {
                    'FirmwareConfiguration', 'HardwareConfiguration', 'ImmutableROM', 'MeasurementManifest',
                    'MutableFirmware', 'MutableFirmwareSecurityVersionNumber', 'MutableFirmwareVersion'
                },
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = spdm_measurement_intf_types.MeasurementType
            },
            ['Measurement'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = spdm_measurement_intf_types.Measurement
            },
            ['LastUpdated'] = {
                ['baseType'] = 'U64',
                ['readOnly'] = true,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = spdm_measurement_intf_types.LastUpdated
            },
            ['PartofSummaryHash'] = {
                ['baseType'] = 'Boolean',
                ['readOnly'] = true,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = spdm_measurement_intf_types.PartofSummaryHash
            },
            ['SecurityVersionNumber'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['options'] = {['emitsChangedSignal'] = 'false'},
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = spdm_measurement_intf_types.SecurityVersionNumber
            }
        },
        ['bmc.kepler.Object.Properties'] = {
            ['ClassName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ClassName
            },
            ['ObjectName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ObjectName
            },
            ['ObjectIdentifier'] = {
                ['baseType'] = 'Struct',
                ['$ref'] = '#/defs/StructIdentifier',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ObjectIdentifier
            }
        }
    },
    ['mdb_classes'] = mdb.get_class_obj(
        '/bmc/kepler/Chassis/:ChassisId/TrustedComponents/:DeviceName/ComponentIntegrity/:Id/Measurements/:Index'),
    ['new_mdb_objects'] = mdb.new_objects_builder({
        ['bmc.kepler.RoT.ComponentIntegrity.SPDMMeasurement'] = {
            ['property_defaults'] = {
                ['Index'] = spdm_measurement_intf_types.Index.default[1],
                ['HashAlgorithm'] = spdm_measurement_intf_types.HashAlgorithm.default[1],
                ['MeasurementType'] = spdm_measurement_intf_types.MeasurementType.default[1],
                ['Measurement'] = spdm_measurement_intf_types.Measurement.default[1],
                ['LastUpdated'] = spdm_measurement_intf_types.LastUpdated.default[1],
                ['PartofSummaryHash'] = spdm_measurement_intf_types.PartofSummaryHash.default[1],
                ['SecurityVersionNumber'] = spdm_measurement_intf_types.SecurityVersionNumber.default[1]
            },
            ['privileges'] = {
                ['props'] = {
                    ['Index'] = {['read'] = privilege.ReadOnly},
                    ['HashAlgorithm'] = {['read'] = privilege.ReadOnly},
                    ['MeasurementType'] = {['read'] = privilege.ReadOnly},
                    ['Measurement'] = {['read'] = privilege.ReadOnly},
                    ['LastUpdated'] = {['read'] = privilege.ReadOnly},
                    ['PartofSummaryHash'] = {['read'] = privilege.ReadOnly},
                    ['SecurityVersionNumber'] = {['read'] = privilege.ReadOnly}
                }
            },
            ['interface_types'] = spdm_measurement_intf_types
        },
        ['bmc.kepler.Object.Properties'] = {
            ['property_defaults'] = {
                ['ClassName'] = properties_intf_types.ClassName.default[1],
                ['ObjectName'] = properties_intf_types.ObjectName.default[1],
                ['ObjectIdentifier'] = properties_intf_types.ObjectIdentifier.default[1]
            },
            ['interface_types'] = properties_intf_types
        }
    })
}

local TrustedComponentCertificate = {
    ['mdb_prop_configs'] = {
        ['bmc.kepler.CertificateService.Certificate'] = {
            ['CertificateType'] = {
                ['baseType'] = 'U32',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.CertificateType
            },
            ['CertificateUsageType'] = {
                ['baseType'] = 'U32',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.CertificateUsageType
            },
            ['Fingerprint'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.Fingerprint
            },
            ['FingerprintHashAlgorithm'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.FingerprintHashAlgorithm
            },
            ['Issuer'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.Issuer
            },
            ['KeyUsage'] = {
                ['baseType'] = 'U32[]',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.KeyUsage
            },
            ['SerialNumber'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.SerialNumber
            },
            ['SignatureAlgorithm'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.SignatureAlgorithm
            },
            ['Subject'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.Subject
            },
            ['ValidNotAfter'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.ValidNotAfter
            },
            ['ValidNotBefore'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.ValidNotBefore
            },
            ['FilePath'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.FilePath
            },
            ['CommonName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.CommonName
            },
            ['CRLStartTime'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.CRLStartTime
            },
            ['CRLExpireTime'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.CRLExpireTime
            },
            ['CertCount'] = {
                ['baseType'] = 'U32',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.CertCount
            },
            ['KeyLength'] = {
                ['baseType'] = 'U32',
                ['readOnly'] = true,
                ['privilege'] = {['read'] = {'ReadOnly'}},
                ['validator'] = certificate_intf_types.KeyLength
            }
        },
        ['bmc.kepler.Object.Properties'] = {
            ['ClassName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ClassName
            },
            ['ObjectName'] = {
                ['baseType'] = 'String',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ObjectName
            },
            ['ObjectIdentifier'] = {
                ['baseType'] = 'Struct',
                ['$ref'] = '#/defs/StructIdentifier',
                ['readOnly'] = true,
                ['validator'] = properties_intf_types.ObjectIdentifier
            }
        }
    },
    ['mdb_method_configs'] = {
        ['bmc.kepler.CertificateService.Certificate'] = {
            ['DeleteCRL'] = {['req'] = {}, ['rsp'] = {}},
            ['GetCertificateString'] = {
                ['req'] = {},
                ['rsp'] = {{['baseType'] = 'String', ['param'] = 'CertificateString'}}
            }
        }
    },
    ['mdb_classes'] = mdb.get_class_obj(
        '/bmc/kepler/Chassis/:ChassisId/TrustedComponents/:DeviceName/Certificates/:SlotId'),
    ['new_mdb_objects'] = mdb.new_objects_builder({
        ['bmc.kepler.CertificateService.Certificate'] = {
            ['property_defaults'] = {
                ['CertificateType'] = certificate_intf_types.CertificateType.default[1],
                ['CertificateUsageType'] = certificate_intf_types.CertificateUsageType.default[1],
                ['Fingerprint'] = certificate_intf_types.Fingerprint.default[1],
                ['FingerprintHashAlgorithm'] = certificate_intf_types.FingerprintHashAlgorithm.default[1],
                ['Issuer'] = certificate_intf_types.Issuer.default[1],
                ['KeyUsage'] = certificate_intf_types.KeyUsage.default[1],
                ['SerialNumber'] = certificate_intf_types.SerialNumber.default[1],
                ['SignatureAlgorithm'] = certificate_intf_types.SignatureAlgorithm.default[1],
                ['Subject'] = certificate_intf_types.Subject.default[1],
                ['ValidNotAfter'] = certificate_intf_types.ValidNotAfter.default[1],
                ['ValidNotBefore'] = certificate_intf_types.ValidNotBefore.default[1],
                ['FilePath'] = certificate_intf_types.FilePath.default[1],
                ['CommonName'] = certificate_intf_types.CommonName.default[1],
                ['CRLStartTime'] = certificate_intf_types.CRLStartTime.default[1],
                ['CRLExpireTime'] = certificate_intf_types.CRLExpireTime.default[1],
                ['CertCount'] = certificate_intf_types.CertCount.default[1],
                ['KeyLength'] = certificate_intf_types.KeyLength.default[1]
            },
            ['privileges'] = {
                ['props'] = {
                    ['CertificateType'] = {['read'] = privilege.ReadOnly},
                    ['CertificateUsageType'] = {['read'] = privilege.ReadOnly},
                    ['Fingerprint'] = {['read'] = privilege.ReadOnly},
                    ['FingerprintHashAlgorithm'] = {['read'] = privilege.ReadOnly},
                    ['Issuer'] = {['read'] = privilege.ReadOnly},
                    ['KeyUsage'] = {['read'] = privilege.ReadOnly},
                    ['SerialNumber'] = {['read'] = privilege.ReadOnly},
                    ['SignatureAlgorithm'] = {['read'] = privilege.ReadOnly},
                    ['Subject'] = {['read'] = privilege.ReadOnly},
                    ['ValidNotAfter'] = {['read'] = privilege.ReadOnly},
                    ['ValidNotBefore'] = {['read'] = privilege.ReadOnly},
                    ['FilePath'] = {['read'] = privilege.ReadOnly},
                    ['CommonName'] = {['read'] = privilege.ReadOnly},
                    ['CRLStartTime'] = {['read'] = privilege.ReadOnly},
                    ['CRLExpireTime'] = {['read'] = privilege.ReadOnly},
                    ['CertCount'] = {['read'] = privilege.ReadOnly},
                    ['KeyLength'] = {['read'] = privilege.ReadOnly}
                }
            },
            ['interface_types'] = certificate_intf_types
        },
        ['bmc.kepler.Object.Properties'] = {
            ['property_defaults'] = {
                ['ClassName'] = properties_intf_types.ClassName.default[1],
                ['ObjectName'] = properties_intf_types.ObjectName.default[1],
                ['ObjectIdentifier'] = properties_intf_types.ObjectIdentifier.default[1]
            },
            ['interface_types'] = properties_intf_types
        }
    })
}

local SpdmComponent = {
    ['prop_configs'] = {
        ['DeviceName'] = {
            ['baseType'] = 'String',
            ['primaryKey'] = true,
            ['usage'] = {'CSR'},
            ['validator'] = spdm_component_class_types.DeviceName
        },
        ['Position'] = {
            ['baseType'] = 'String',
            ['usage'] = {'CSR'},
            ['validator'] = spdm_component_class_types.Position
        },
        ['SystemId'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U8',
            ['readOnly'] = true,
            ['validator'] = spdm_component_class_types.SystemId
        },
        ['DevBus'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U8',
            ['readOnly'] = true,
            ['validator'] = spdm_component_class_types.DevBus
        },
        ['DevDevice'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U8',
            ['readOnly'] = true,
            ['validator'] = spdm_component_class_types.DevDevice
        },
        ['DevFunction'] = {
            ['usage'] = {'CSR'},
            ['baseType'] = 'U8',
            ['readOnly'] = true,
            ['validator'] = spdm_component_class_types.DevFunction
        },
        ['Eid'] = {['baseType'] = 'U8', ['readOnly'] = true, ['validator'] = spdm_component_class_types.Eid},
        ['Phyaddr'] = {['baseType'] = 'U16', ['readOnly'] = true, ['validator'] = spdm_component_class_types.Phyaddr}
    },
    ['default_props'] = {
        ['DeviceName'] = spdm_component_class_types.DeviceName.default[1],
        ['Position'] = spdm_component_class_types.Position.default[1],
        ['SystemId'] = spdm_component_class_types.SystemId.default[1],
        ['DevBus'] = spdm_component_class_types.DevBus.default[1],
        ['DevDevice'] = spdm_component_class_types.DevDevice.default[1],
        ['DevFunction'] = spdm_component_class_types.DevFunction.default[1],
        ['Eid'] = spdm_component_class_types.Eid.default[1],
        ['Phyaddr'] = spdm_component_class_types.Phyaddr.default[1]
    }
}

local M = {}

function M.init(bus)
    class('TrustedComponent', TrustedComponent):set_bus(bus)
    class('ComponentIntegrity', ComponentIntegrity):set_bus(bus)
    class('SPDMMeasurement', SPDMMeasurement):set_bus(bus)
    class('TrustedComponentCertificate', TrustedComponentCertificate):set_bus(bus)
    class('SpdmComponent', SpdmComponent):set_bus(bus)
end

-- The callback needs to be registered during app initialization
function M.ImplComponentIntegrityMeasurementSetSPDMGetSignedMeasurements(cb)
    class('ComponentIntegrity')['bmc.kepler.RoT.ComponentIntegrity.MeasurementSet'].SPDMGetSignedMeasurements =
        function(obj, ctx, ...)
            local req = measurement_set_intf_types.SPDMGetSignedMeasurementsReq.new(...):validate(nil, nil, true)
            local rsp =
                measurement_set_intf_types.SPDMGetSignedMeasurementsRsp.new(cb(obj, ctx, req:unpack())):validate()
            return rsp:unpack(true)
        end
end

-- The callback needs to be registered during app initialization
function M.ImplTrustedComponentCertificateCertificateDeleteCRL(cb)
    class('TrustedComponentCertificate')['bmc.kepler.CertificateService.Certificate'].DeleteCRL =
        function(obj, ctx, ...)
            local req = certificate_intf_types.DeleteCRLReq.new(...):validate(nil, nil, true)
            local rsp = certificate_intf_types.DeleteCRLRsp.new(cb(obj, ctx, req:unpack())):validate()
            return rsp:unpack(true)
        end
end

-- The callback needs to be registered during app initialization
function M.ImplTrustedComponentCertificateCertificateGetCertificateString(cb)
    class('TrustedComponentCertificate')['bmc.kepler.CertificateService.Certificate'].GetCertificateString = function(
        obj, ctx, ...)
        local req = certificate_intf_types.GetCertificateStringReq.new(...):validate(nil, nil, true)
        local rsp = certificate_intf_types.GetCertificateStringRsp.new(cb(obj, ctx, req:unpack())):validate()
        return rsp:unpack(true)
    end
end

return M
